<?php

/**
 * This is the model class for table "{{mem_pro}}".
 *
 * The followings are the available columns in table '{{mem_pro}}':
 * @property integer $zm_id
 * @property integer $zar_id
 * @property string $zmp_firstname
 * @property string $zmp_lastname
 * @property string $zmp_nickname
 * @property integer $zmp_sex
 * @property integer $zmp_birthday
 * @property string $zmp_tel
 * @property string $zmp_qq
 * @property string $zmp_msn
 * @property string $zmp_icq
 * @property string $zmp_yahoo
 * @property string $zmp_skype
 * @property string $zmp_address
 * @property integer $zmp_zip
 * @property string $zmp_siteurl
 * @property string $zmp_alipay
 * @property string $zmp_bank_user
 * @property string $zmp_bank_name
 * @property string $zmp_bank_account
 * @property string $zmp_bank_address
 */
class MemPro extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return MemPro the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	//定义主键
	public function primaryKey(){
		return 'zm_id';
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{mem_pro}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zmp_nickname, zmp_lastname, zmp_qq, zar_id, zmp_address', 'required'),
			array('zm_id, zar_id, zmp_sex, zmp_zip', 'numerical', 'integerOnly'=>true),
			array('zmp_firstname, zmp_lastname, zmp_nickname, zmp_bank_user', 'length', 'max'=>50),
			array('zmp_tel', 'length', 'max'=>11),
			array('zmp_qq', 'length', 'max'=>15),
			array('zmp_msn, zmp_yahoo, zmp_skype', 'length', 'max'=>100),
			array('zmp_icq', 'length', 'max'=>20),
			array('zmp_address, zmp_siteurl, zmp_alipay, zmp_bank_name, zmp_bank_address', 'length', 'max'=>255),
			array('zmp_bank_account', 'length', 'max'=>25),			
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zm_id, zar_id, zmp_firstname, zmp_lastname, zmp_nickname, zmp_sex, zmp_birthday, zmp_tel, zmp_qq, zmp_msn, zmp_icq, zmp_yahoo, zmp_skype, zmp_address, zmp_zip, zmp_siteurl, zmp_alipay, zmp_bank_user, zmp_bank_name, zmp_bank_account, zmp_bank_address', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zm_id' => 'Zm',
			'zar_id' => '所在地区',
			'zmp_firstname' => '姓名',
			'zmp_lastname' => '真实姓名',
			'zmp_nickname' => '昵称',
			'zmp_sex' => '性别',
			'zmp_birthday' => '生日',
			'zmp_tel' => '电话号码',
			'zmp_qq' => 'QQ',
			'zmp_msn' => 'Msn',
			'zmp_icq' => 'Icq',
			'zmp_yahoo' => 'Yahoo',
			'zmp_skype' => 'Skype',
			'zmp_address' => '联系地址',
			'zmp_zip' => '邮编',
			'zmp_siteurl' => '个人网站',
			'zmp_alipay' => '支付宝账号',
			'zmp_bank_user' => '银行开户名',
			'zmp_bank_name' => '银行名字',
			'zmp_bank_account' => '银行账号',
			'zmp_bank_address' => '银行地址',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('zm_id',$this->zm_id);
		$criteria->compare('zar_id',$this->zar_id);
		$criteria->compare('zmp_firstname',$this->zmp_firstname,true);
		$criteria->compare('zmp_lastname',$this->zmp_lastname,true);
		$criteria->compare('zmp_nickname',$this->zmp_nickname,true);
		$criteria->compare('zmp_sex',$this->zmp_sex);
		$criteria->compare('zmp_birthday',$this->zmp_birthday);
		$criteria->compare('zmp_tel',$this->zmp_tel,true);
		$criteria->compare('zmp_qq',$this->zmp_qq,true);
		$criteria->compare('zmp_msn',$this->zmp_msn,true);
		$criteria->compare('zmp_icq',$this->zmp_icq,true);
		$criteria->compare('zmp_yahoo',$this->zmp_yahoo,true);
		$criteria->compare('zmp_skype',$this->zmp_skype,true);
		$criteria->compare('zmp_address',$this->zmp_address,true);
		$criteria->compare('zmp_zip',$this->zmp_zip);
		$criteria->compare('zmp_siteurl',$this->zmp_siteurl,true);
		$criteria->compare('zmp_alipay',$this->zmp_alipay,true);
		$criteria->compare('zmp_bank_user',$this->zmp_bank_user,true);
		$criteria->compare('zmp_bank_name',$this->zmp_bank_name,true);
		$criteria->compare('zmp_bank_account',$this->zmp_bank_account,true);
		$criteria->compare('zmp_bank_address',$this->zmp_bank_address,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

		
	//获取模型验证失败信息，返回字符串
	public function getErrorsStr(){
		header("Content-type:text/html;charset=utf-8");
		$errors = $this->getErrors();
		$message = '对不起，数据验证失败。信息如下：';
		foreach($errors as $key=>$value){
			$message .= '<br/>'.$key.'：';
			foreach($value as $key1=>$value1){
				$message .= $key1+1;
				$message .= '.'.$value1;		
			}
			return $message;
		}
	}
}